|
1
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
'use strict'; |
|
4
|
|
|
|
|
5
|
|
|
let { errorHandlers } = require("../utils/listeners"); |
|
6
|
|
|
|
|
7
|
|
|
const bSecurePaymentTransactionURL = "https://api.bsecure.pk/v1/payment-plugin/create-order"; |
|
8
|
|
|
|
|
9
|
|
|
var _require = require("./"), |
|
10
|
|
|
isEmpty = _require.isEmpty, |
|
11
|
|
|
prepareFrame = _require.prepareFrame; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
function generateOrder(TransactionParameters) { |
|
15
|
|
|
const xhttp = new XMLHttpRequest(); |
|
16
|
|
|
xhttp.onreadystatechange = function () { |
|
17
|
|
|
var _data = this; |
|
18
|
|
|
if (this.readyState == 4) { |
|
19
|
|
|
var _responseObj = JSON.parse(_data.response); |
|
20
|
|
|
if (!isEmpty(_responseObj.body) && this.status == 200) { |
|
21
|
|
|
if (!isEmpty(_responseObj.body.checkout_url)) { |
|
22
|
|
|
prepareFrame(_responseObj.body.checkout_url); |
|
23
|
|
|
} else { |
|
24
|
|
|
errorHandlers.handleErrors(_responseObj); |
|
25
|
|
|
} |
|
26
|
|
|
} else { |
|
27
|
|
|
errorHandlers.handleErrors(_responseObj); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
}; |
|
31
|
|
|
|
|
32
|
|
|
xhttp.open("POST", bSecurePaymentTransactionURL, true); |
|
33
|
|
|
xhttp.setRequestHeader("Content-Type", "application/json"); |
|
34
|
|
|
xhttp.send(JSON.stringify({ |
|
35
|
|
|
"redirect_url": TransactionParameters.__20red__, |
|
36
|
|
|
"plugin_version": TransactionParameters.__18ver__, |
|
37
|
|
|
"hash": TransactionParameters.__17seh__, |
|
38
|
|
|
"merchant_id": TransactionParameters.__15mid__, |
|
39
|
|
|
"store_id": TransactionParameters.__16stid__, |
|
40
|
|
|
"txn_reference": TransactionParameters.__02trdt__, |
|
41
|
|
|
"env_id": parseInt(TransactionParameters.__21cenv__), |
|
42
|
|
|
"customer": { |
|
43
|
|
|
"name": TransactionParameters.__06cname__, |
|
44
|
|
|
"email": TransactionParameters.__09cemail__, |
|
45
|
|
|
"country_code": TransactionParameters.__07ccc__, |
|
46
|
|
|
"phone_number": TransactionParameters.__08cphn__ |
|
47
|
|
|
}, |
|
48
|
|
|
"customer_address": { |
|
49
|
|
|
"country": TransactionParameters.__10ccc__, |
|
50
|
|
|
"province": TransactionParameters.__11cstate__, |
|
51
|
|
|
"city": TransactionParameters.__12ccity__, |
|
52
|
|
|
"area": TransactionParameters.__13carea__, |
|
53
|
|
|
"address": TransactionParameters.__14cfadd__ |
|
54
|
|
|
}, |
|
55
|
|
|
"order": { |
|
56
|
|
|
"order_id": TransactionParameters.__00trid__, |
|
57
|
|
|
"currency": TransactionParameters.__01curr__, |
|
58
|
|
|
"sub_total_amount": TransactionParameters.__03stamt__, |
|
59
|
|
|
"discount_amount": TransactionParameters.__04damt__, |
|
60
|
|
|
"total_amount": TransactionParameters.__05tamt__ |
|
61
|
|
|
} |
|
62
|
|
|
})); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
module.exports = { |
|
66
|
|
|
generateOrder: generateOrder, |
|
67
|
|
|
}; |